<script setup lang="ts">
import { reactive, ref } from 'vue';

const formRef = ref();
const state = reactive({
  ruleForm: {
    id: '',
    account: '',
    username: '',
    telephone: '',
    email: '',
    sex: null,
    avatar: ''
  },
  rules: {
    username: {
      required: true, message: '请输入姓名名称', trigger: ['blur']
    },
    telephone: {
      required: true, message: '请输入手机号码', trigger: ['blur']
    },
  },
  source: {},
});
const changeAvatar = (source:Api.Common.FileSource) => {
  state.source = source;
  state.ruleForm.avatar = source.id;
};
defineExpose({
  state,
  formRef
});
</script>

<template>
  <n-form ref="formRef" :model="state.ruleForm" :rules="state.rules" label-placement="left" label-width="100" require-mark-placement="left">
    <n-grid responsive="screen" item-responsive>
      <n-form-item-gi span="24" label="登录账号" path="account">
        <n-input v-model:value="state.ruleForm.account" placeholder="请输入登录账号" clearable></n-input>
      </n-form-item-gi>
      <n-form-item-gi span="24" label="姓名" path="username">
        <n-input v-model:value="state.ruleForm.username" placeholder="请输入姓名" clearable></n-input>
      </n-form-item-gi>
      <n-form-item-gi span="24" label="手机号码" path="telephone">
        <n-input v-model:value="state.ruleForm.telephone" placeholder="请输入手机号码" clearable></n-input>
      </n-form-item-gi>
      <n-form-item-gi span="24" label="邮箱" path="email">
        <n-input v-model:value="state.ruleForm.email" placeholder="请输入邮箱" clearable></n-input>
      </n-form-item-gi>
      <n-form-item-gi span="24" label="性别" path="sex">
        <n-radio-group v-model:value="state.ruleForm.sex">
          <n-radio :value="1">男</n-radio>
          <n-radio :value="2">女</n-radio>
        </n-radio-group>
      </n-form-item-gi>
      <n-form-item-gi span="24" label="头像" path="avatar">
        <CommonUploadImg :source="state.source" accept-file=".jpg,.png,.jpeg"
                         module-name="user" :max="1" @change="changeAvatar" />
      </n-form-item-gi>
    </n-grid>
  </n-form>
</template>

<style scoped>

</style>
